<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use Symfony\Component\Filesystem\Filesystem;

class InitDirectoryCommand extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('my:initDirectory')
            ->setDescription('初始化项目目录');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('start');
        $output->writeln('');

        $fileSystem = new Filesystem;
        $other_dirs = ['runtime', 'vendor'];// 其它需要授权的目录
        foreach($other_dirs as $other_dir){
            $output->writeln(root_path().$other_dir);
        }

        $dirs = ['tmp', 'uploads'];
        foreach($dirs as $dir){
            if ($fileSystem->exists($dir) === false)
            {
                $output->writeln("正在新建目录: {$dir}");
                $fileSystem->mkdir(public_path().$dir, 0777);
            } else {
                $output->writeln("目录已存在: {$dir}");
            }
        }

        $output->writeln('');
        $output->writeln('end');
    }
}
